home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / combi030.zip / CMB_DEMO.C next >
C/C++ Source or Header  |  1991-10-26  |  5KB  |  143 lines

  1. /*    COMBI-Disk demonstration/test program
  2.     by Vadim V. Vlasov, Moscow, 1991.
  3.  
  4.     Usage:
  5.  
  6.     cmb_demo [d:]
  7.  
  8.     where "d" is a drive letter.
  9.  
  10.   The program works as following. It opens 3 files for stream output
  11.     and 3 files through handle. Then writes a text to 1st file(s),
  12.     then to 2nd one and 3rd one. Then again writes to 1st file,
  13.     closes 3rd and deletes 3rd. And at last it writes again into 2nd
  14.     file. As a result 4 files are produced which occupy clusters
  15.     not contiguously but rather mixed with other files. Moreover
  16.     a gap due to 3d file (which is deleted) is produced. See the
  17.     disk usage map for these files! Nevertheless, COMBI-Disk manages
  18.     memory usage correctly. You may run this program first for hard disk
  19.     (use e.g. "c:" parameter) and then for COMBI-Disk's RAM disk.
  20.     After that's done just compare the produced files for the two
  21.     drives. They should be identical.
  22.     You may wish to change 'repetition' constant to increase files'
  23.     sizes thus contracting space used for cache and see that if
  24.     some space (larger than your hard disk's track size) is left on
  25.     RAM disk the cache is working.
  26.     You may also interrupt (via CTRL-BREAK) this program after the
  27.     prompt "This is a second attempt... press a key...". Then the
  28.     3rd file will not be deleted and you may see its contents.
  29.  
  30. */
  31.  
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <io.h>
  35. #include <fcntl.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #define  repetition 20
  39. main(int argc, char *argv[])
  40.      {
  41.      FILE   *f1,*f2,*f3;        /* for 3 streams                  */
  42.      int    fh1,fh2,fh3;        /* for 3 files opened with handle */
  43.      int    i,len;
  44.      char   *fname, *prompt="\npress a key...";
  45.      char   *trouble="\nCan't open file!?\n";
  46.      char   *text1="This text is written to file #1...\n";
  47.      char   *text2="This text is written to file #2...\nFile #1 is still open.\n";
  48.      char   *text3="This text is written to file #3...\nFiles #1 & #2 open.\n";
  49.      char   *text4="This is second attempt to write into file #1...\nFiles #2 & #3 open.\n";
  50.      char   *text5="Now we write again into file #1...\nSo far file #3 is deleted.\n";
  51.      char   *text6="Text for file #2...\n";
  52.  
  53.      fname=strdup(argv[1]);
  54.      strcat(fname,"file1.fil");
  55.      if((f1=fopen(fname,"wt"))==NULL)
  56.         printf("%s: %s", fname, trouble);
  57.      fname=strdup(argv[1]);
  58.      strcat(fname,"file1.hnd");
  59.      fh1=open(fname,O_RDWR|O_CREAT|O_TRUNC|O_TEXT,S_IWRITE|S_IREAD);
  60.      if(fh1==-1)
  61.         {printf("%s: %s",fname,trouble); exit(1);}
  62.      printf("File #1 opened.\n");
  63.      printf("%s %s",text1,prompt);
  64.      len=strlen(text1);
  65.      for(i=0;i<repetition;i++)
  66.         {
  67.          fprintf(f1,text1);
  68.          write(fh1,text1,len);
  69.         }
  70.      getch();
  71.      fname=strdup(argv[1]);
  72.      strcat(fname,"file2.fil");
  73.      f2=fopen(fname,"wt");
  74.      fname=strdup(argv[1]);
  75.      strcat(fname,"file2.hnd");
  76.      fh2=open(fname,O_RDWR|O_CREAT|O_TRUNC,0200|0400);
  77.      if( (f2==NULL)||(fh2==-1))
  78.         {printf(trouble); exit(1);}
  79.      printf("File #2 opened.\n");
  80.      printf("%s %s",text2,prompt);
  81.      len=strlen(text2);
  82.      for(i=0;i<repetition;i++)
  83.         {
  84.          fprintf(f2,text2);
  85.          write(fh2,text2,len);
  86.         }
  87.      getch();
  88.      fname=strdup(argv[1]);
  89.      strcat(fname,"file3.fil");
  90.      f3=fopen(fname,"wt");
  91.      fname=strdup(argv[1]);
  92.      strcat(fname,"file3.hnd");
  93.      fh3=open(fname,O_RDWR|O_CREAT|O_TRUNC,0200|0400);
  94.      if( (f3==NULL)||(fh3==-1))
  95.         {printf(trouble); exit(1);}
  96.      printf("File #3 opened.\n");
  97.      printf("%s %s",text3,prompt);
  98.      len=strlen(text3);
  99.      for(i=0;i<repetition;i++)
  100.         {
  101.          fprintf(f3,text3);
  102.          write(fh3,text3,len);
  103.         }
  104.      getch();
  105.      printf("%s %s",text4,prompt);
  106.      len=strlen(text4);
  107.      for(i=0;i<repetition;i++)
  108.         {
  109.          fprintf(f1,text4);
  110.          write(fh1,text4,len);
  111.         }
  112.      getch();
  113.      if(fclose(f3) || close(fh3))
  114.         {printf("Can't close file #3???\n");
  115.          exit(1);}
  116.      remove(fname);
  117.      fname=strdup(argv[1]);
  118.      strcat(fname,"file3.fil");
  119.      remove(fname);
  120.      printf("%s %s","File #3 deleted.\n",prompt);
  121.      printf("%s %s",text5,prompt);
  122.      len=strlen(text5);
  123.      for(i=0;i<repetition;i++)
  124.         {
  125.          fprintf(f1,text5);
  126.          write(fh1,text5,len);
  127.         }
  128.      getch();
  129.      printf("%s %s",text6,prompt);
  130.      len=strlen(text6);
  131.      for(i=0;i<repetition;i++)
  132.         {
  133.          fprintf(f2,text6);
  134.          write(fh2,text6,len);
  135.         }
  136.      getch();
  137.      printf("    Good bye!!!\n");
  138.      fcloseall();
  139.      close(fh1);
  140.      close(fh2);
  141.      return(0);
  142.      }
  143.